local tr = aegisub.gettext

script_name = tr"一键拍词"
script_description = tr"一键拍词"
script_author = "Wandway"
script_version = "1.0.2.4"
script_last_update_time = '2013/10/10'


function one_key_timing(subs, sel)
	-- 获取当前选中行
	local line = subs[sel[1]]

	-- 当没有加载视频时退出一键拍词脚本，并开个玩笑
	local video_file = aegisub.project_properties()["video_file"]
	if #video_file == 0 then aegisub.debug.out("拍什么鬼？") return end

	-- 设置当前行结束时间
	if line.class == "dialogue" then
		local video_position = aegisub.project_properties()["video_position"]
		line.end_time = aegisub.ms_from_frame(video_position)
		subs[sel[1]] = line
	end

	if sel[1] < #subs then
	-- 设置下一行开始时间
		local line_next = subs[sel[1] + 1]
		line_next.start_time = line.end_time + 1	
		if line_next.end_time == 0 then
			line_next.end_time = line_next.start_time + string.len(line_next.text) * 60
		end
		subs[sel[1] + 1] = line_next
	-- 跳转到下一行
		sel[1] = sel[1] + 1	
	else
		aegisub.debug.out("拍完了！拍完啦！拍完呐！")
	end
	return sel
end

aegisub.register_macro(script_name, script_description, one_key_timing)
